package Vocabulary.Test;//package Vocabulary.Test;
//
//import javazoom.jl.decoder.JavaLayerException;
//import javazoom.jl.player.advanced.AdvancedPlayer;
//import javazoom.jl.player.advanced.PlaybackEvent;
//import javazoom.jl.player.advanced.PlaybackListener;
//import javazoom.jl.player.advanced.PlaybackEventCode;
//
//import java.io.FileInputStream;
//import java.io.IOException;
//
//public class MP3Player {
//    public static void main(String[] args) {
//        String mp3FilePath = "path/to/your/file.mp3";
//
//        try {
//            FileInputStream fileInputStream = new FileInputStream(mp3FilePath);
//            AdvancedPlayer player = new AdvancedPlayer(fileInputStream);
//
//            player.setPlayBackListener(new PlaybackListener() {
//                @Override
//                public void playbackFinished(PlaybackEvent evt) {
//                    if (evt.getType() == PlaybackEventCode.STOPPED) {
//                        System.out.println("Playback stopped");
//                    }
//                }
//            });
//
//            player.play();
//        } catch (JavaLayerException | IOException e) {
//            e.printStackTrace();
//        }
//    }
//}
import javazoom.jl.player.Player;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import java.io.*;

public class MP3Player {

    public static void main(String[] args) {
    }
    public void play() throws Exception {
        FileInputStream fileInputStream = new FileInputStream("src\\main\\java\\Vocabulary\\Test\\wool.wav");
        Player player = new Player(fileInputStream);
        player.play();
    }
    public static FileInputStream convertByteToInputStream(byte[] byteData) {
        try {
            // 创建临时文件并写入 byte[] 数据
            File tempFile = File.createTempFile("tempfile", ".tmp");
            FileOutputStream fos = new FileOutputStream(tempFile);
            fos.write(byteData);
            fos.close();

            // 创建 FileInputStream 对象
            return new FileInputStream(tempFile);
        } catch (IOException e) {
            e.printStackTrace();
            return null; // 发生异常时返回 null
        }
    }
}